package com.ruoyi.web.product;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.product.domain.vo.RecommendVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.Recommend;
import com.ruoyi.product.service.IRecommendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;


/**
 * 推荐商品Controller
 *
 * @author jtm
 * @date 2024-12-07
 */
@RestController
@RequestMapping("/product/recommend")
public class RecommendController extends BaseController
{
    @Autowired
    private IRecommendService recommendService;

    /**
     * admin || commonAdmin
     * 查询推荐商品列表
     */
    @PreAuthorize("@ss.hasPermi('product:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecommendVo recommendVo)
    {
        startPage();
        List<RecommendVo> list = recommendService.selectRecList(recommendVo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('product:recommend:list')")
    @GetMapping("/ulist")
    public TableDataInfo ulist(RecommendVo recommendVo){
        startPage();
        List<RecommendVo> list = recommendService.selectUserRecList(recommendVo);
        return getDataTable(list);
    }

    /**
     * 导出推荐商品列表
     */
    @PreAuthorize("@ss.hasPermi('product:recommend:export')")
    @Log(title = "推荐商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Recommend recommend)
    {
        List<Recommend> list = recommendService.selectRecommendList(recommend);
        ExcelUtil<Recommend> util = new ExcelUtil<Recommend>(Recommend.class);
        util.exportExcel(response, list, "推荐商品数据");
    }

    /**
     * 获取推荐商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:recommend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recommendService.selectRecommendById(id));
    }

    /**
     * 新增推荐商品
     */
    @PreAuthorize("@ss.hasPermi('product:recommend:add')")
    @Log(title = "推荐商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Recommend recommend)
    {
        return toAjax(recommendService.insertRecommend(recommend));
    }

    /**
     * 修改推荐商品
     */
    @PreAuthorize("@ss.hasPermi('product:recommend:edit')")
    @Log(title = "推荐商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Recommend recommend)
    {
        return toAjax(recommendService.updateRecommend(recommend));
    }

    /**
     * 删除推荐商品
     */
    @PreAuthorize("@ss.hasPermi('product:recommend:remove')")
    @Log(title = "推荐商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recommendService.deleteRecommendByIds(ids));
    }
}
